package akka.http.scaladsl.marshallers.json4s

import akka.http.scaladsl.marshalling._
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.model.{ContentTypes, HttpCharsets}
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import akka.stream.Materializer
import org.json4s._

import scala.language.implicitConversions

/**
  * A trait providing automatic to and from JSON marshalling/unmarshalling using an in-scope *spray-json* protocol.
  */
trait PlayJsonSupport {

//  implicit def json4sMarshaller[T <: AnyRef]: ToEntityMarshaller[JValue] =
//    Marshaller.StringMarshaller.wrap(ContentTypes.`application/json`)(serialization.write)
//
//
//  implicit def json4sJsValueUnmarshaller(implicit mat: Materializer): FromEntityUnmarshaller[JValue] =
//    Unmarshaller.byteStringUnmarshaller.forContentTypes(`application/json`).mapWithCharset { (data, charset) ⇒
//      val input = if (charset == HttpCharsets.`UTF-8`) data.toString() else data.decodeString(charset.nioCharset.name)
//      serialization.read(input)
//    }
//
}



